﻿using System;
using System.Web.UI.WebControls;
using eCommerce.core;
using eCommerce.core.Helpers;
using eCommerce.db.BORespository;

namespace eCommerce.web.Controls.Common
{
    public partial class NavigatorProduct : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rptCategory.DataSource = CategoryBo.GetListByParentId((int)CategoryType.Product, (int)CategoryType.Root, (int)CategoryType.Active);
                rptCategory.DataBind();
            }
        }

        protected void rptCategory_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var rptSubCategory = (Repeater)e.Item.FindControl("rptSubCategory");
                var categoryId     = Utils.ToInt32(((HiddenField)e.Item.FindControl("hfCategoryId")).Value);
                
                rptSubCategory.DataSource = CategoryBo.GetListByParentId((int)CategoryType.Product, categoryId, (int)CategoryType.Active);
                rptSubCategory.DataBind();
            }
        }       
    }
}